﻿Imports System.Security.Cryptography
Imports System.Text.RegularExpressions
Imports AutoCAD

Public Class TestForm
    Private cadApplicationService As ICadApplicationService = New CadApplicationServiceImpl
    Private cadBlockReferenceService As ICadBlockReferenceService = New CadBlockReferenceServiceImpl
    Private cadPlateService As ICadPlateService = New CadPlateServiceImpl
    Private cadEntityDataService As ICadEntityDataService = New CadEntityDataServiceImpl
    Private cadDrawService As ICadDrawService = New CadDrawServiceImpl
    Private Sub btn_根据快引用构建ucs_Click(sender As Object, e As EventArgs) Handles btn_根据快引用构建ucs.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument
        Dim br As AcadBlockReference = cadApplicationService.GetEntity(doc)
        Dim ucs As AcadUCS = cadBlockReferenceService.GetOCS(br)
        ucs.Origin = br.InsertionPoint
        doc.ActiveUCS = ucs
        br.Update()
    End Sub

    Private Sub btn_将实体转为板件_Click(sender As Object, e As EventArgs) Handles btn_将实体转为板件.Click
        Dim ent As AcadEntity = cadApplicationService.GetEntity
        Dim doc As AcadDocument = ent.Document
        If Not cadEntityDataService.IsSolid(ent) Then
            doc.Utility.Prompt("非【三维实体】,不能转换为【板件】")
        End If
        cadPlateService.SolidToPlate(ent)
    End Sub

    Private Sub btn_初始化图层_Click(sender As Object, e As EventArgs) Handles btn_初始化图层.Click
        cadApplicationService.BuildLayer()
    End Sub

    Private Sub btn_对象矩阵转换_Click(sender As Object, e As EventArgs) Handles btn_对象矩阵转换.Click
        Dim ent As AcadEntity = cadApplicationService.GetEntity
        Dim angle(2) As Double
        angle(0) = Math.PI / 4
        'angle(2) = Math.PI / 4

        cadApplicationService.RotateEntity(ent, angle)
        Dim p() As Double = cadApplicationService.Rotate3D(New Double() {100, 0, 0}, angle)
        Dim doc As AcadDocument = ent.Document

        cadDrawService.DrawPoint(doc.ModelSpace, p)
    End Sub

    Private Sub btn_构建一个工件_Click(sender As Object, e As EventArgs) Handles btn_构建一个工件.Click
        Dim dt As New DataTable()
        With dt.Columns
            .Add("px", GetType(Double))
            .Add("py", GetType(Double))
            .Add("pz", GetType(Double))
            .Add("rx", GetType(Double))
            .Add("ry", GetType(Double))
            .Add("rz", GetType(Double))
            .Add("sx", GetType(Double))
            .Add("sy", GetType(Double))
            .Add("sz", GetType(Double))
        End With

        Dim dr As DataRow = dt.NewRow
        With dr
            .Item("px") = 100
            .Item("py") = 100
            .Item("pz") = 100
            .Item("rx") = 90
            .Item("ry") = 0
            .Item("rz") = 0
            .Item("sx") = 900
            .Item("sy") = 500
            .Item("sz") = 18
        End With

        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument
        cadPlateService.DrawPlate(doc, dr)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim ent As AcadEntity '= cadApplicationService.GetEntity

        Dim cadDrawHoleService As ICadDrawHoleService = New CadDrawHoleServiceImpl

        For Each ent In cadApplicationService.GetCurrentSelectSet
            If cadEntityDataService.IsBlockReference(ent) Then
                Dim c1 As AcadEntity = cadDrawHoleService.DrawHole_平面(ent, 34, 70, 25, 15, -17)
                c1.color = ACAD_COLOR.acRed

                Dim c2 As AcadEntity = cadDrawHoleService.DrawHole_侧面(ent, 0, 70, 25 / 2, 8, 34)
                c2.color = ACAD_COLOR.acRed

                Dim c4 As AcadEntity = cadDrawHoleService.DrawHole_侧面(ent, 0, 70, 25 / 2, 10, -12)
                c4.color = ACAD_COLOR.acRed

                Dim c3 As AcadEntity = cadDrawHoleService.DrawHole_侧面(ent, 0, 70 + 32, 25 / 2, 8, 22)
                c3.color = ACAD_COLOR.acRed

                Dim c5 As AcadEntity = cadDrawHoleService.DrawHole_侧面(ent, 0, 70 + 32, 25 / 2, 8, -12)
                c5.color = ACAD_COLOR.acRed




            End If
        Next ent


    End Sub

    ''' <summary>
    ''' 测试批量绘制连接件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btn_测试批量绘制孔_Click(sender As Object, e As EventArgs) Handles btn_测试批量绘制孔.Click



        测试自动绘制孔位2()

    End Sub

    Sub 测试自动绘制孔位1()
        Dim dt As New DataTable
        With dt.Columns
            .Add("id", GetType(Integer))
            .Add("组名", GetType(String))
            .Add("孔名", GetType(String))
            .Add("所在面", GetType(Integer))
            .Add("无效", GetType(Boolean))
            .Add("孔径", GetType(Double))
            .Add("孔深", GetType(Double))
            .Add("px", GetType(Double))
            .Add("py", GetType(Double))
            .Add("pz", GetType(Double))
        End With

        With dt.Rows
            .Add(New Object() {1, "左侧第1组", "偏心轮", 5, False, 15, -17, 34, 70, 25})
            .Add(New Object() {2, "左侧第1组", "连接杆", 2, False, 8, 34, 0, 70, 12.5})
            .Add(New Object() {3, "左侧第1组", "预埋母", 2, False, 10, -12, 0, 70, 12.5})
            .Add(New Object() {4, "左侧第1组", "8x22木榫孔", 2, False, 8, 22, 0, 102, 12.5})
            .Add(New Object() {5, "左侧第1组", "8x12木榫孔", 2, False, 8, -12, 0, 102, 12.5})
            .Add(New Object() {7, "左侧第2组", "偏心轮", 5, False, 15, -17, 34, 430, 25})
            .Add(New Object() {8, "左侧第2组", "连接杆", 2, False, 8, 34, 0, 430, 12.5})
            .Add(New Object() {9, "左侧第2组", "预埋母", 2, False, 10, -12, 0, 430, 12.5})
            .Add(New Object() {10, "左侧第2组", "8x22木榫孔", 2, False, 8, 22, 0, 398, 12.5})
            .Add(New Object() {11, "左侧第2组", "8x12木榫孔", 2, False, 8, -12, 0, 398, 12.5})
            .Add(New Object() {13, "左侧第3组", "偏心轮", 5, False, 15, -17, 34, 250, 25})
            .Add(New Object() {14, "左侧第3组", "连接杆", 2, False, 8, 34, 0, 250, 12.5})
            .Add(New Object() {15, "左侧第3组", "预埋母", 2, False, 10, -12, 0, 250, 12.5})
            .Add(New Object() {16, "左侧第3组", "8x22木榫孔", 2, False, 8, 22, 0, 282, 12.5})
            .Add(New Object() {17, "左侧第3组", "8x12木榫孔", 2, False, 8, -12, 0, 282, 12.5})
            .Add(New Object() {18, "左侧第3组", "8x22木榫孔", 2, False, 8, 22, 0, 218, 12.5})
            .Add(New Object() {19, "左侧第3组", "8x12木榫孔", 2, False, 8, -12, 0, 218, 12.5})
            .Add(New Object() {21, "右侧第1组", "偏心轮", 5, False, 15, -17, 766, 70, 25})
            .Add(New Object() {22, "右侧第1组", "连接杆", 3, False, 8, -34, 800, 70, 12.5})
            .Add(New Object() {23, "右侧第1组", "预埋母", 3, False, 10, 12, 800, 70, 12.5})
            .Add(New Object() {24, "右侧第1组", "8x22木榫孔", 3, False, 8, -22, 800, 102, 12.5})
            .Add(New Object() {25, "右侧第1组", "8x12木榫孔", 3, False, 8, 12, 800, 102, 12.5})
            .Add(New Object() {27, "右侧第2组", "偏心轮", 5, False, 15, -17, 766, 430, 25})
            .Add(New Object() {28, "右侧第2组", "连接杆", 3, False, 8, -34, 800, 430, 12.5})
            .Add(New Object() {29, "右侧第2组", "预埋母", 3, False, 10, 12, 800, 430, 12.5})
            .Add(New Object() {30, "右侧第2组", "8x22木榫孔", 3, False, 8, -22, 800, 398, 12.5})
            .Add(New Object() {31, "右侧第2组", "8x12木榫孔", 3, False, 8, 12, 800, 398, 12.5})
            .Add(New Object() {33, "右侧第3组", "偏心轮", 5, False, 15, -17, 766, 250, 25})
            .Add(New Object() {34, "右侧第3组", "连接杆", 3, False, 8, -34, 800, 250, 12.5})
            .Add(New Object() {35, "右侧第3组", "预埋母", 3, False, 10, 12, 800, 250, 12.5})
            .Add(New Object() {36, "右侧第3组", "8x22木榫孔", 3, False, 8, -22, 800, 282, 12.5})
            .Add(New Object() {37, "右侧第3组", "8x12木榫孔", 3, False, 8, 12, 800, 282, 12.5})
            .Add(New Object() {38, "右侧第3组", "8x22木榫孔", 3, False, 8, -22, 800, 250 - 32, 12.5})
            .Add(New Object() {39, "右侧第3组", "8x12木榫孔", 3, False, 8, 12, 800, 250 - 32, 12.5})
        End With

        Dim ent As AcadEntity
        Dim c1 As AcadEntity
        Dim cadDrawHoleService As ICadDrawHoleService = New CadDrawHoleServiceImpl
        For Each ent In cadApplicationService.GetCurrentSelectSet
            If cadEntityDataService.IsBlockReference(ent) Then
                For Each dr As DataRow In dt.Rows
                    Select Case dr("所在面")
                        Case 0
                            c1 = cadDrawHoleService.DrawHole_平面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 1
                            c1 = cadDrawHoleService.DrawHole_立面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 2
                            c1 = cadDrawHoleService.DrawHole_侧面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 3
                            c1 = cadDrawHoleService.DrawHole_侧面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 4
                            c1 = cadDrawHoleService.DrawHole_立面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 5
                            c1 = cadDrawHoleService.DrawHole_平面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                    End Select

                    c1.color = ACAD_COLOR.acRed
                Next dr
            End If
        Next ent
    End Sub

    Sub 测试自动绘制孔位2()
        Dim esi As New ExpressionServiceImpl

        Dim dt As New DataTable
        With dt.Columns
            .Add("id", GetType(Integer))
            .Add("组名", GetType(String))
            .Add("孔名", GetType(String))
            .Add("所在面", GetType(String))
            .Add("无效", GetType(String))
            .Add("孔径", GetType(String))
            .Add("孔深", GetType(String))
            .Add("px", GetType(String))
            .Add("py", GetType(String))
            .Add("pz", GetType(String))
        End With

        With dt.Rows
            .Add(New Object() {"1", "左侧第1组", "偏心轮", "5", "1==1", "15", "17", "34", "70", "#sz"})
            .Add(New Object() {"2", "左侧第1组", "连接杆", "2", "1==1", "8", "34", "0", "70", "#sz/2"})
            .Add(New Object() {"3", "左侧第1组", "预埋母", "2", "1==1", "10", "-12", "0", "70", "#sz/2"})
            .Add(New Object() {"4", "左侧第1组", "8x22木榫孔", "2", "1==1", "8", "22", "0", "70+32", "#sz/2"})
            .Add(New Object() {"5", "左侧第1组", "8x12木榫孔", "2", "1==1", "8", "-12", "0", "70+32", "#sz/2"})
            .Add(New Object() {"7", "左侧第2组", "偏心轮", "5", "1==1", "15", "17", "34", "#sy-70", "#sz"})
            .Add(New Object() {"8", "左侧第2组", "连接杆", "2", "1==1", "8", "34", "0", "#sy-70", "#sz/2"})
            .Add(New Object() {"9", "左侧第2组", "预埋母", "2", "1==1", "10", "-12", "0", "#sy-70", "#sz/2"})
            .Add(New Object() {"10", "左侧第2组", "8x22木榫孔", "2", "1==1", "8", "22", "0", "#sy-70-32", "#sz/2"})
            .Add(New Object() {"11", "左侧第2组", "8x12木榫孔", "2", "1==1", "8", "-12", "0", "#sy-70-32", "#sz/2"})
            .Add(New Object() {"13", "左侧第3组", "偏心轮", "5", "1==1", "15", "17", "34", "#sy/2", "#sz"})
            .Add(New Object() {"14", "左侧第3组", "连接杆", "2", "1==1", "8", "34", "0", "#sy/2", "#sz/2"})
            .Add(New Object() {"15", "左侧第3组", "预埋母", "2", "1==1", "10", "-12", "0", "#sy/2", "#sz/2"})
            .Add(New Object() {"16", "左侧第3组", "8x22木榫孔", "2", "1==1", "8", "22", "0", "#sy/2+32", "#sz/2"})
            .Add(New Object() {"17", "左侧第3组", "8x12木榫孔", "2", "1==1", "8", "-12", "0", "#sy/2+32", "#sz/2"})
            .Add(New Object() {"18", "左侧第3组", "8x22木榫孔", "2", "1==1", "8", "22", "0", "#sy/2-32", "#sz/2"})
            .Add(New Object() {"19", "左侧第3组", "8x12木榫孔", "2", "1==1", "8", "-12", "0", "#sy/2-32", "#sz/2"})
            .Add(New Object() {"21", "右侧第1组", "偏心轮", "5", "1==1", "15", "17", "#sx-34", "70", "#sz"})
            .Add(New Object() {"22", "右侧第1组", "连接杆", "3", "1==1", "8", "34", "#sx", "70", "#sz/2"})
            .Add(New Object() {"23", "右侧第1组", "预埋母", "3", "1==1", "10", "-12", "#sx", "70", "#sz/2"})
            .Add(New Object() {"24", "右侧第1组", "8x22木榫孔", "3", "1==1", "8", "22", "#sx", "70+32", "#sz/2"})
            .Add(New Object() {"25", "右侧第1组", "8x12木榫孔", "3", "1==1", "8", "-12", "#sx", "70+32", "#sz/2"})
            .Add(New Object() {"27", "右侧第2组", "偏心轮", "5", "1==1", "15", "17", "#sx-34", "#sy-70", "#sz"})
            .Add(New Object() {"28", "右侧第2组", "连接杆", "3", "1==1", "8", "34", "#sx", "#sy-70", "#sz/2"})
            .Add(New Object() {"29", "右侧第2组", "预埋母", "3", "1==1", "10", "-12", "#sx", "#sy-70", "#sz/2"})
            .Add(New Object() {"30", "右侧第2组", "8x22木榫孔", "3", "1==1", "8", "22", "#sx", "#sy-70-32", "#sz/2"})
            .Add(New Object() {"31", "右侧第2组", "8x12木榫孔", "3", "1==1", "8", "-12", "#sx", "#sy-70-32", "#sz/2"})
            .Add(New Object() {"33", "右侧第3组", "偏心轮", "5", "1==1", "15", "17", "#sx-34", "#sy/2", "#sz"})
            .Add(New Object() {"34", "右侧第3组", "连接杆", "3", "1==1", "8", "34", "#sx", "#sy/2", "#sz/2"})
            .Add(New Object() {"35", "右侧第3组", "预埋母", "3", "1==1", "10", "-12", "#sx", "#sy/2", "#sz/2"})
            .Add(New Object() {"36", "右侧第3组", "8x22木榫孔", "3", "1==1", "8", "22", "#sx", "#sy/2+32", "#sz/2"})
            .Add(New Object() {"37", "右侧第3组", "8x12木榫孔", "3", "1==1", "8", "-12", "#sx", "#sy/2+32", "#sz/2"})
            .Add(New Object() {"38", "右侧第3组", "8x22木榫孔", "3", "1==1", "8", "22", "#sx", "#sy/2-32", "#sz/2"})
            .Add(New Object() {"39", "右侧第3组", "8x12木榫孔", "3", "1==1", "8", "-12", "#sx", "#sy/2-32", "#sz/2"})

        End With


        Dim dt1 As New DataTable
        With dt1.Columns
            .Add("id", GetType(Integer))
            .Add("组名", GetType(String))
            .Add("孔名", GetType(String))
            .Add("所在面", GetType(Integer))
            .Add("无效", GetType(Boolean))
            .Add("孔径", GetType(Double))
            .Add("孔深", GetType(Double))
            .Add("px", GetType(Double))
            .Add("py", GetType(Double))
            .Add("pz", GetType(Double))
        End With

        Dim plate As PlateEntity
        For Each dr As DataRow In dt.Rows
            plate = New PartEntity
            With plate
                .sx = 800
                .sy = 500
                .sz = 25
            End With

            Dim newdr As DataRow = dt1.NewRow
            newdr("id") = esi.eavl_plate(plate, dr("id"))
            newdr("组名") = String.Concat("'", dr("组名"), "'")
            newdr("孔名") = String.Concat("'", dr("孔名"), "'")
            newdr("所在面") = esi.eavl_plate(plate, dr("所在面"))
            newdr("无效") = esi.eavl_plate(plate, dr("无效"))
            newdr("孔径") = esi.eavl_plate(plate, dr("孔径"))
            newdr("孔深") = IIf(newdr("所在面") = 5 Or newdr("所在面") = 4 Or newdr("所在面") = 3, -1, 1) * esi.eavl_plate(plate, dr("孔深"))
            newdr("px") = esi.eavl_plate(plate, dr("px"))
            newdr("py") = esi.eavl_plate(plate, dr("py"))
            newdr("pz") = esi.eavl_plate(plate, dr("pz"))
            dt1.Rows.Add(newdr)
        Next dr


        Dim ent As AcadEntity
        Dim c1 As AcadEntity
        Dim cadDrawHoleService As ICadDrawHoleService = New CadDrawHoleServiceImpl
        For Each ent In cadApplicationService.GetCurrentSelectSet
            If cadEntityDataService.IsBlockReference(ent) Then
                For Each dr As DataRow In dt1.Rows
                    Select Case dr("所在面")
                        Case 0
                            c1 = cadDrawHoleService.DrawHole_平面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 1
                            c1 = cadDrawHoleService.DrawHole_立面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 2
                            c1 = cadDrawHoleService.DrawHole_侧面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 3
                            c1 = cadDrawHoleService.DrawHole_侧面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 4
                            c1 = cadDrawHoleService.DrawHole_立面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                        Case 5
                            c1 = cadDrawHoleService.DrawHole_平面(ent, dr("px"), dr("py"), dr("pz"), dr("孔径"), dr("孔深"))
                    End Select

                    c1.color = ACAD_COLOR.acRed
                Next dr
            End If
        Next ent
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim db As IMySqlService = New MySqlServiceImpl
        db.connection()
        db.update("truncate test")
        Dim sql As String = "insert into test(id)values(1),(2),(3)"
        db.insert(sql)
        Dim dt As DataTable = db.select("select * from test")
        MsgBox(dt.Rows.Count)
    End Sub

    ''' <summary>
    ''' 通过获取数据库中的数据,绘制孔
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btn_数据绘制孔_Click(sender As Object, e As EventArgs) Handles btn_数据绘制孔.Click
        Dim expressionServic As IExpressionService = New ExpressionServiceImpl
        Dim db As IMySqlService = New MySqlServiceImpl
        db.connection()

        ' 拾取板件
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet
        For Each br As AcadEntity In ss
            If cadEntityDataService.IsBlockReference(br) Then

                Dim sx, sy, sz As Double
                sx = br.XScaleFactor
                sy = br.YScaleFactor
                sz = br.ZScaleFactor



                ' 获取孔数据
                Dim dt As DataTable = db.select("select * from hole_scheme_line where head_id = 2")
                For Each dr As DataRow In dt.Rows ' 负值
                    dr("sx") = Math.Abs(sx)
                    dr("sy") = Math.Abs(sy)
                    dr("sz") = Math.Abs(sz)
                Next

                ' 生成孔列表

                Dim lt As New List(Of HoleEntity)
                Dim hole As HoleEntity
                For Each dr As DataRow In dt.Rows
                    If expressionServic.eavl(dr, dr("inhibition")) <> True Then '没有抑制的情况下, 生成孔数据
                        hole = New HoleEntity
                        With hole
                            .face = dr("face")
                            .diameter = expressionServic.eavl(dr, dr("diameter"))
                            .depth = expressionServic.eavl(dr, dr("depth"))
                            .px = expressionServic.eavl(dr, dr("px"))
                            .py = expressionServic.eavl(dr, dr("py"))
                            .pz = expressionServic.eavl(dr, dr("pz"))
                        End With
                        lt.Add(hole)
                    End If
                Next

                ' 绘制孔
                Dim cadDrawHoleService As ICadDrawHoleService = New CadDrawHoleServiceImpl
                For Each hole In lt
                    cadDrawHoleService.DrawHole(hole.face, br, hole.px, hole.py, hole.pz, hole.diameter, hole.depth)
                Next

            End If
        Next
    End Sub

    Private Sub btn_孔位工具_Click(sender As Object, e As EventArgs) Handles btn_孔位工具.Click
        Dim app As AcadApplication = cadApplicationService.GetApplication
        Dim fm As New form_孔位工具
        With fm

        End With
    End Sub

    Private Sub btn_选中对象转换为工件_Click(sender As Object, e As EventArgs) Handles btn_选中对象转换为工件.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument()
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet

        Dim cadPartService As ICadPartService = New CadPartServiceImpl
        cadPartService.TranslateToPart(doc, ss)
    End Sub

    ''' <summary>
    ''' 展平空间
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument()
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet

        Dim cadPartService As ICadPartService = New CadPartServiceImpl
        cadPartService.CopyAndExpandPart(doc, ss)
    End Sub

    '创建三视图
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument()
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet

        Dim cadPartService As ICadPartService = New CadPartServiceImpl
        cadPartService.CreateThreeViews(doc, ss)
    End Sub

    ' 创建工件数据表
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument()
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet

        Dim cadPartService As ICadPartService = New CadPartServiceImpl
        Dim dt As DataTable = cadPartService.BuildPartDataTable()
        DataGridView1.DataSource = dt
        DataGridView1.AutoResizeColumns()
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim brs As ICadBlockReferenceService = New CadBlockReferenceServiceImpl()
        Dim ent As AcadEntity = cadApplicationService.GetEntity
        Dim br As AcadBlockReference = ent
        brs.镜像法线(ent)
    End Sub

    '测试法线旋转
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        'Dim handle As String = "2b2"
        'Dim br As AcadBlockReference = cadApplicationService.HandleToObject(handle)
        'Dim a As Double() = New Double() {tb_x.Text, tb_y.Text, tb_z.Text}
        'Dim r As Double = Math.PI / 180


        'Dim position() As Double = br.InsertionPoint
        'br.InsertionPoint = New Double() {0, 0, 0}

        'Dim angle As Double() = New Double() {a(0) * r, a(1) * r, a(2) * r}
        'Dim n As Double() = New Double() {0, 0, 1}
        'br.Normal = cadApplicationService.Rotate3D2(n, angle)

        'br.InsertionPoint = position
        'br.Update()
        ttt()
    End Sub

    Private Sub ttt()
        Dim handle As String = "2b2"
        Dim br As AcadBlockReference = cadApplicationService.HandleToObject(handle)
        Dim a As Double() = New Double() {tb_x.Text, tb_y.Text, tb_z.Text}
        Dim r As Double = Math.PI / 180


        Dim position() As Double = br.InsertionPoint
        br.InsertionPoint = New Double() {0, 0, 0}
        br.Normal = New Double() {0, 0, 1}
        br.Rotation = 0

        Dim angle As Double() = New Double() {tb_x.Text * r, tb_y.Text * r, tb_z.Text * r}
        'Dim n As Double() = New Double() {0, 0, 1}
        'br.Normal = cadApplicationService.Rotate3D2(n, angle)

        br.Rotate3D(New Double() {0, 0, 0}, New Double() {1, 0, 0}, angle(0))
        br.Rotate3D(New Double() {0, 0, 0}, New Double() {0, 1, 0}, angle(1))
        br.Rotate3D(New Double() {0, 0, 0}, New Double() {0, 0, 1}, angle(2))



        'br.InsertionPoint = position
        br.Update()
    End Sub




    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click

        Dim dt As New DataTable
        With dt.Columns
            .Add("f1")
            .Add("f2")
        End With

        Dim dr As DataRow = dt.NewRow
        dr(0) = 1
        dr(1) = 5



        Dim dict As New Dictionary(Of String, String)
        dict.Add("a", "b")
        pg.SelectedObject = dict

    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        'Dim mapper As PolyLineDataMapper = New PolyLineDataMapper
        'Dim ent1 As PolyLineDataEntity = New PolyLineDataEntity
        'With ent1
        '    .id = 10
        '    .name = "bb2"
        '    .remark = "bbb2"
        '    .coordinates = New Double() {1.0#, 2.0#, 3.0#}.ToList
        '    .bluges = New Double() {1.0#, 2.0#, 3.0#}.ToList
        'End With
        'Dim ent2 As PolyLineDataEntity = New PolyLineDataEntity
        'With ent2
        '    .id = 10
        '    .name = "bb1"
        '    .remark = "bbb1"
        '    .coordinates = New Double() {1.0#, 2.0#, 3.0#}.ToList
        '    .bluges = New Double() {1.0#, 2.0#, 3.0#}.ToList
        'End With

        'MsgBox(mapper.Insert(New PolyLineDataEntity() {ent1, ent2}.ToList))


        'MsgBox(evalService.Eval(str))
        'Dim match As Match = evalService.GetMatch_ByParent(str)
        'MsgBox(evalService.GetMatchFullValue(match))

        'Dim parent As New Dictionary(Of String, String)
        'Dim self As New Dictionary(Of String, String)

        'parent.Add("x", 1)
        'self.Add("x", 2)

        Dim p As New PartEntity
        Dim s As New PartEntity
        p.sx = 1
        s.sx = 2


        Dim evalService As IEvalService = New EvalServiceImpl
        Dim str As String = TextBox1.Text

        Try
            'str = evalService.AnalyzeExpressions_ByDict(str, self, parent)
            str = evalService.AnalyzeExpressions_ByEntity(str, s, p)
            MsgBox(str)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument
        Dim br As AcadBlockReference = doc.HandleToObject("290")
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet(doc)

        cadApplicationService.ActivationWCS() ' 激活WCS
        cadBlockReferenceService.CopyObjectsToBlock(br, ss)
        br.Update()
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Dim doc As AcadDocument = cadApplicationService.GetActiveDocument
        Dim br As AcadBlockReference = doc.HandleToObject("290")
        Dim ss As AcadSelectionSet = cadApplicationService.GetCurrentSelectSet(doc)
        cadBlockReferenceService.MoveObjectsToBlockReference(br, ss)
    End Sub

    ''' <summary>
    ''' 测试绘制孔位
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btn_testHole_Click(sender As Object, e As EventArgs) Handles btn_testHole.Click
        Dim cadDrawHole As New CadDrawHole2ServiceImpl
        DataGridView1.DataSource = cadDrawHole.test2()
    End Sub
End Class
